package com.doublefish.doublefishrobot.ui.setting;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.doublefish.doublefishrobot.R;
import com.doublefish.doublefishrobot.base.BaseActivity;
import com.doublefish.doublefishrobot.utils.LocalizationUtils;
import com.doublefish.doublefishrobot.widget.CommonDialog;

import butterknife.BindView;
import butterknife.OnClick;

public class LanguageActivity extends BaseActivity {
    @BindView(R.id.tv_title)
    TextView titleTv;

    @BindView(R.id.iv_tick1)
    ImageView tickIv1;

    @BindView(R.id.iv_tick2)
    ImageView tickIv2;

    @BindView(R.id.iv_tick0)
    ImageView tickIv0;

    private int languageType = 0;

    @Override
    protected int getLayoutId() {
        return R.layout.activty_language;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        languageType = LocalizationUtils.getInstance().getLanguageType();
        showUIWithType(languageType);
    }

    @Override
    protected void initListener() {

    }

    private void showUIWithType(int type) {
        if (type == 1) {
            //中文
            tickIv0.setVisibility(View.INVISIBLE);
            tickIv1.setVisibility(View.VISIBLE);
            tickIv2.setVisibility(View.INVISIBLE);
        } else if (type == 2) {
            //english
            tickIv0.setVisibility(View.INVISIBLE);
            tickIv1.setVisibility(View.INVISIBLE);
            tickIv2.setVisibility(View.VISIBLE);
        } else {
            //auto
            tickIv0.setVisibility(View.VISIBLE);
            tickIv1.setVisibility(View.INVISIBLE);
            tickIv2.setVisibility(View.INVISIBLE);
        }
    }

    private void saveConfig(int type) {
        if (type == languageType) {
            return;
        }
        languageType = type;
        LocalizationUtils.getInstance().setLanguageType(type);
        //弹窗提示重启
        showLanguageAlert();
    }

    private void showLanguageAlert() {
        String title = getString(R.string.language_alert_1);
        String msg = getString(R.string.language_alert_2);
        CommonDialog dialog = new CommonDialog(this, title, msg, null);
        dialog.setPositiveButton(getString(R.string.ok));
        dialog.setShowNegativeButton(false);
        dialog.show();
    }

    @OnClick({R.id.ll_type_0, R.id.ll_type_1, R.id.ll_type_2})
    public void onCLickView(View view) {
        switch (view.getId()) {
            case R.id.ll_type_0: {
                showUIWithType(0);
                saveConfig(0);
            }
            break;

            case R.id.ll_type_1: {
                showUIWithType(1);
                saveConfig(1);
            }
            break;

            case R.id.ll_type_2: {
                showUIWithType(2);
                saveConfig(2);
            }
            break;
        }
    }

    @OnClick(R.id.ll_back)
    public void onBackBtnClick() {
        finish();
    }

}
